package com.biubiushop.util;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;

@Data
@MappedSuperclass
public class BaseEntity implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 1L;

    @Id
    @Column(nullable = false, columnDefinition = "char(32)")
    @GenericGenerator(name = "uuid_Generator", strategy = "uuid")
    @GeneratedValue(generator = "uuid_Generator")
    private String id;

    /**
     * 此字段弃之不用,插入时会有默认值,但不会更新,不做任何处理
     */
    @Column(nullable = false, insertable = false, updatable = false, columnDefinition = "bit(1) DEFAULT b'1' COMMENT '是否逻辑删除(0-true，1-false)'")
    private Integer hasDelete;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(nullable = false, columnDefinition = "datetime COMMENT '创建时间'")
    private Date createTime;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(columnDefinition = "datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP")
    private Date updateTime;
}
